package com.wjh.test;

import com.wjh.bean.Order;
import com.wjh.bean.User;
import com.wjh.mapper.UserMaper;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.Before;
import org.junit.Test;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;


public class Spring_mybatis_test {
    private SqlSessionFactory factory=null;
    @Before
    public void init() throws IOException {
        String str="mybatis-config.xml";
        InputStream in= Resources.getResourceAsStream(str);
        factory=new SqlSessionFactoryBuilder().build(in);

    }
    @Test
    public void getuserbyid(){
        SqlSession session=factory.openSession();
        UserMaper maper=session.getMapper(UserMaper.class);
        User user=maper.getuserbyid(1);
        System.out.println(user);

    }
    @Test
    public void getuserorder(){
        SqlSession session=factory.openSession();
        UserMaper maper=session.getMapper(UserMaper.class);
        List<Order> list=maper.getuserorder(1);
        System.out.println(list);
    }
}
